import { defineStore } from 'pinia'
import type { ThreatRecord } from '../types/threat'

export const useThreatStore = defineStore('threat', {
  state: () => ({
    threats: [] as ThreatRecord[],
    loading: false,
    error: null as string | null,
  }),
  
  actions: {
    async fetchThreats() {
      this.loading = true
      try {
        // 模拟API调用
        const mockData: ThreatRecord[] = [
          {
            id: 'ee110625',
            sensor: 'blitvencia',
            events: 4345,
            severity: 'high',
            firstSeen: '2024-01-24 06:54:48',
            lastSeen: '2024-01-24 18:01:32',
            sparkline: [1, 2, 3, 4, 5],
            srcIp: '192.168.1.1',
            srcPort: null,
            dstIp: '23.253.126.58',
            dstPort: 53,
            protocol: 'UDP',
            type: 'DNS',
            info: 'gamarue (malware)',
            reference: 'static',
            tags: ['malware'],
          },
          // 添加更多模拟数据...
        ]
        this.threats = mockData
      } catch (error) {
        this.error = '获取威胁数据失败'
      } finally {
        this.loading = false
      }
    }
  }
}) 